#include <ctime>
#include <iostream>
#include <fstream>

using namespace std;

void bubbleSort(int list[], int LL) {
	while(LL--) 	{
		bool swapped = false;

		for(int l = 0; l < LL; l++) {
			if(list[l] > list[l + 1]){
				swap(list[l], list[l + 1]);
				swapped = true;
			}
		}

		if(swapped == false) break;
	}
}

void read_from_file(const char *filename, int a[], int length) {
    ifstream file(filename);

    for(int l=0; l < length; l++)
        file >> a[l];
}

int main()
{
    #define LEN 5000
    int c[LEN];
    read_from_file("m1_sorted.txt",c,LEN);
    unsigned int startT =  clock();
    bubbleSort(c,LEN);
    unsigned int finishT = clock();
    unsigned int workT = finishT - startT;
    cout<<"m1_sorted " << workT << " milliseconds \n";

    read_from_file("m2_reverse.txt",c,LEN);
    startT =  clock();
    bubbleSort(c,LEN);
    finishT = clock();
    workT = finishT - startT;
    cout<<"m2_reverse " << workT << " milliseconds \n";

    read_from_file("m3_shuffle.txt",c,LEN);
    startT =  clock();
    bubbleSort(c,LEN);
    finishT = clock();
    workT = finishT - startT;
    cout<<"m3_shuffle " << workT << " milliseconds \n";
    return 0;
}
